package logic

import (
	"context"

	"server-go/rpc/reward/internal/models"
	"server-go/rpc/reward/internal/svc"
	"server-go/rpc/reward/types/reward"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateBaseInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateBaseInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateBaseInfoLogic {
	return &UpdateBaseInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateBaseInfoLogic) UpdateBaseInfo(in *reward.UpdateBaseInfoInput) (*reward.UpdateBaseInfoOutput, error) {
	out := &reward.UpdateBaseInfoOutput{}
	usersDao := &models.UsersDao{
		Email: in.Email,
	}
	if err := usersDao.First(l.svcCtx.Db); err != nil {
		return out, err
	}
	out = &reward.UpdateBaseInfoOutput{
		NickName:  usersDao.Nickname,
		Email:     usersDao.Email,
		Gender:    usersDao.Gender,
		UserIntro: usersDao.Userintro,
		UserName:  usersDao.Username,
		Money:     uint32(usersDao.Money),
	}
	return out, nil
}
